#include "fxcc/core/graph/common/ActorLoader.h"

using namespace fxcc::graph::common;


std::unordered_map<std::string, std::shared_ptr<AnimationController>> ActorLoader::m_Actors;

bool ActorLoader::LoadFile(const fxcc::File& file)
{
    return LoadActor(file.m_RelativePath).get();
}

std::shared_ptr<AnimationController> ActorLoader::LoadActor(const std::string& path)
{
    auto it = m_Actors.find(path);
    if (it != m_Actors.end())
    {
        return it->second;
    }

    fxcc::yml::Serializer serialzer;;

    auto inst = std::make_shared<AnimationController>();
    bool flag = serialzer.DecodePath<AnimationController>(path, *inst);

    if (flag) {
        m_Actors[path] = inst;
        return inst;
    }
    return 0;
}
